package com.xcx.eduservice.controller.aclcontroller;


import com.xcx.commonuntils.returnuntls.ErrorEnum;
import com.xcx.commonuntils.returnuntls.ReturnMessage;
import com.xcx.commonuntils.returnuntls.ReturnMessageUtils;
import com.xcx.eduservice.request.aclrequest.companyrequest.CompanyRequest;
import com.xcx.eduservice.request.aclrequest.companyrequest.GetCoByNameRequest;
import com.xcx.eduservice.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 团队表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Api(tags = "团队管理api")
@RestController
@RequestMapping("/acl/company")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
@CrossOrigin

public class CompanyController {

    final public CompanyService service;



    /**
     * 手动新增团队公司
     * */
    @ApiOperation(value = "新增团队")
    @PostMapping("save")
    public ReturnMessage<Object> addCompany(@RequestBody @Valid CompanyRequest respVo, BindingResult br) {
        if (br.hasErrors()) {
            return ReturnMessageUtils.errorWithEum(ErrorEnum.E_REQUEST_PARAM_ERROR);
        }
        return service.addCompany(respVo);
    }

    @ApiOperation(value = "通过名称或者性质查询公司/团队")
    @PostMapping("queryCompanyByNL")
    public ReturnMessage<Object> queryCompanyByNL(@RequestBody @Valid GetCoByNameRequest respVo, BindingResult br) {
        if (br.hasErrors()) {
            return ReturnMessageUtils.errorWithEum(ErrorEnum.E_REQUEST_PARAM_ERROR);
        }
        return service.queryCompanyByNL(respVo);
    }








}
